﻿create PROCEDURE Sync.SP_LoanExecutionAttachments_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanExecutionAttachmentID],
		g.[LoanExecutionID],g.[Attachment],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanExecutionAttachments] g RIGHT JOIN Sync.LoanExecutionAttachments_Tracking t  
    ON t.LoanExecutionAttachmentID = g.LoanExecutionAttachmentID 
    join LoanExecution le on le.LoanExecutionID = g.LoanExecutionID
join CustomerLoans cl
on le.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
		AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END











